I have a loop over all my observations to write out data in a special way. I want to specify variables to be written in a -file write- statement with local macros. So, instead of
I want to replace var[i] with a local macro with the same content. I can get
var[`i'] into a macro, but I can't use that macro. For example:
By escaping the backquote with the backslash I get the `i' into the macro but it disappears when the macro is evaluated. Naturally, because `i' evaluates to a null string. The same thing happens in -file write-. I figured that there would be a way to escape the quotes, but putting additional backslashes in front of the backquote doesn't help. Here it is with an extra slash:
So, is there a way to get the backslash into the macro definition? Any suggestions appreciated. Note that -export delimited- won't meet my needs and there would be serious support issues with requiring Python. The documentation for the escape character is on page 16 of https://www.stata.com/manuals/pmacro.pdf but it doesn't seem to address this sort of recursion.
Code:
file open handle using "filename.raw",write local N=_N forvalues i=1/`N' { file write handle var[`i'] _n }
I want to replace var[i] with a local macro with the same content. I can get
var[`i'] into a macro, but I can't use that macro. For example:
Code:
local mac var[\`i'] . macro list _mac _mac: var[`i'] . di "`mac'" var[]
Code:
. local mac var[\\`i'] . macro list _mac _mac: var[\] . di "`mac'" var[\]
Comment